<?php
class CResponse {
	
	public function __construct(){
		
	}
	
	
	public function location($url){
		header('Location: '. $url);
	}
	
	public function setHeader($str){
		header($str);
	}
	
	public function sendDownload($filepath, $alias = null){
		
		$bufsize = 20000;
		if(file_exists($filepath) && $fh = fopen($filepath, "rb")){
			header('Content-Type: application/force-download');
			header('Content-Disposition: attachment; filename="'.($alias != null ? $alias : pathinfo($filepath, PATHINFO_BASENAME)).'"');
			header('Content-Length: '.filesize($filepath));
			while($buf = fread($fh, $bufsize))
				print $buf;
			fclose($fh);
		}
		else
		{
			header("HTTP/1.1 404 Not Found");
		}
	}
}

?>